<script lang="ts" setup>
import to from 'await-to-js'
import type { FormInstance } from 'element-plus'
import type { UserInfo, HandleType } from './data'

// const data = [
//   {
//     order: '100100001',
//     pull: '100100001',
//     order: '100100001'
//   }
// ]
defineOptions({
  name: 'UserDetail'
})
const emit = defineEmits(['close'])
const props = defineProps<{
  currentRow: UserInfo | undefined
  type: HandleType
}>()
const title = '能力拉取记录'
const isLoading = ref(false)
const tableData = ref([
  {
    houtai: '100100001',
    email: '中国移动通信集团河北有限公司',
    use: '能力使用',
    time: '2024-1-13 21:10:10',
    userName: '叶静宜',
    status: '已拉取'
  }
])
const ruleFormRef = ref<FormInstance>()
const dialogVisible = ref<boolean>(true)

const data = reactive({
  ruleForm: {
    approve: true
  },
  rules: {
    userId: [{ required: true, message: '请填写' }],
    roleIds: [{ required: true, message: '请选择' }]
  }
})
const { ruleForm, rules } = toRefs<any>(data)

const handleSubmit = async () => {
  const validate = await to(ruleFormRef.value.validate())
  if (!validate[1]) return
  const data = JSON.parse(JSON.stringify(ruleForm.value))
  isLoading.value = true
  const [err] = await to(props.type === 'add' ? addUser(data) : editUser(data))
  isLoading.value = false
  if (err) return
  ElMessage.success('操作成功')
  emit('close', true)
}

onMounted(() => {
  if (props.currentRow) {
    const data = JSON.parse(JSON.stringify(props.currentRow))
    // ruleForm.value = data
  }
})
</script>

<template>
  <el-dialog v-model="dialogVisible" :title="title" width="1000px" class="one-dialog" draggable @close="emit('close')">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="110px"
      :disabled="type === 'detail'"
      class="mr-10 one-edit-form">
      <el-table ref="tableRef" :data="tableData" border class="ml-4">
        <el-table-column type="index" label="序号" align="center" width="60" />
        <el-table-column prop="houtai" label="拉取单号 " align="center" show-overflow-tooltip />
        <el-table-column prop="email" label="拉取单位" align="center" show-overflow-tooltip />
        <el-table-column prop="use" label="拉取用途" align="center" show-overflow-tooltip />
        <el-table-column prop="time" label="拉取时间" align="center" show-overflow-tooltip />
        <el-table-column prop="userName" label="拉取人" align="center" show-overflow-tooltip />
        <el-table-column prop="status" label="状态" align="center" show-overflow-tooltip />
      </el-table>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </span>
    </template>
  </el-dialog>
</template>
./data
